package com.ext.aic.utils;

import android.content.Context;
import android.os.Looper;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

import com.eyinfo.android_pure_utils.HandlerManager;
import com.lxj.xpopup.util.XPopupUtils;

import es.dmoral.toasty.Toasty;

public class ToastyUtils {
    private static volatile ToastyUtils instance;

    public static ToastyUtils getInstance() {
        if (instance == null) {
            synchronized (ToastyUtils.class) {
                if (instance == null) {
                    instance = new ToastyUtils();
                }
            }
        }
        return instance;
    }

    private Context context;

    public void config(Context context) {
        this.context = context;
        Toasty.Config.getInstance()
                .tintIcon(false)
                .setTextSize(12)
                .allowQueue(false)
                .setGravity(Gravity.BOTTOM | Gravity.CENTER)
                .supportDarkTheme(true)
                .setRTL(true)
                .apply();
    }

    public void show(String message) {
        if (TextUtils.isEmpty(message)) {
            return;
        }
        Toast custom = Toasty.custom(context, message,
                null,
                0xff1f1f1f,
                0xfff1f1f1,
                Toast.LENGTH_SHORT,
                false,
                true);
        float offset = XPopupUtils.getScreenHeight(context) * .16f;
        custom.setGravity(Gravity.BOTTOM, 0, (int) offset);
        custom.show();
    }
}
